<template>
  <div class="add">
    <!-- 访问全局公共数据，在template中this.$store.state.count中的this可以省略 -->
    <!-- <h3>当前count：{{ $store.state.count }}</h3> -->
    <h3>{{ $store.getters.show }}</h3>
    <button @click="add">+1</button>
    <button @click="addN">+N</button>
    <p>异步操作，一秒后count+</p>
    <button @click="addAsync">异步+1</button>
    <button @click="addNAsync">异步+n</button>
  </div>
</template>
<script>
export default {
  data() {
    return {};
  },
  methods: {
    add() {
      this.$store.commit("add");
    },
    addN() {
      this.$store.commit("addN", 3); //commit调用mutations中的函数
    },
    addAsync() {
      this.$store.dispatch("addasync"); //dispatch调用action中的函数
    },
    addNAsync() {
      this.$store.dispatch("addNasync", 3); //actions传参
    },
  },
};
</script>
